import Vue from 'vue'
import VueRouter from 'vue-router'
import Movie from '@/views/movie/index.vue'
import MovieP from '@/views/movie/playing.vue'
import MovieF from '@/views/movie/feature.vue'
import MovieD from '@/views/movie/detail.vue'
import Cinema from '@/views/cinema/index.vue'
import CinemaD from '@/views/cinema/detail.vue'
import News from '@/views/news/index.vue'
import My from '@/views/my/index.vue'
import City from '@/views/city/index.vue'
import NotFound from '@/Error/NotFound.vue'
import Login from '@/views/login/index.vue'
Vue.use(VueRouter)

// 处理路由跳转到当前页报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}
const routes = [
  {
    path: '/login',
    component: Login
  },
  {
    path: '/',
    redirect: '/movie/playing'
  },
  {
    path: '/movie',
    component: Movie,
    children: [
      {
        path: 'playing',
        component: MovieP
      },
      {
        path: 'feature',
        component: MovieF
      },
      {
        path: 'detail',
        component: MovieD
      }
    ]
  },
  {
    path: '/cinema',
    component: Cinema
  },
  {
    path: '/cinema/detail',
    component: CinemaD
  },
  {
    path: '/news',
    component: News
  },
  {
    path: '/my',
    component: My
  },
  {
    path: '/city',
    component: City
  },
  {
    // 404路由
    path: '*',
    component: NotFound
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
